Run a flow on a schedule or on a trigger
A flow on the line rarely waits for someone to press a button. It starts by itself: every few seconds, at a set time of day, or when a signal arrives from a sensor or a PLC. Three of Node-RED's own nodes do the timing: «inject» repeats or runs at set times, «delay» holds a message back, and «trigger» notices when the signals stop. In this guide you set up all three in a flow of your own.
What you will learn
- How to start a flow every few seconds, or at a set time
- How to wait a moment after a signal before acting
- How to raise an alarm when the signals stop
Before you start
You need a flow of your own to work in; the basics of the editor are in Introduction to Node-RED. Here an inject node named «part detected» stands for the signal of a sensor: press its button to send one.
1. Repeat an inject node
Type inject in «filter nodes», drag an inject node onto the workspace and add a debug node after it. Open the inject node, set «Repeat» to «interval» and «every» to 2 seconds. Each message carries the time it was sent in msg.payload.

2. Deploy and watch it run
Click «Done» and «Deploy». The inject node sends a message every 2 seconds from now on, and the debug panel fills with them. That is how a flow polls a camera or a folder on its own. «Inject once after» also sends one as soon as the flow starts.

3. Run it at a set time instead
Open the inject node again and set «Repeat» to «at a specific time». Write the time, here 06:00, and untick the days it should not run: here Saturday and Sunday, for a check at the start of every working day. «interval between times» repeats only between two times of the day, such as during a shift.

4. Wait a moment after a signal
Click «Done» and «Deploy»: the messages stop until 06:00. Below, the «part detected» inject node stands for a sensor; on a line it would be the input node of a PLC, a serial port or MQTT. Add a delay node between it and the debug node «take a picture», open it and set «For» to 2 seconds. Each message waits that long before it goes on, as a part takes a moment to travel from the sensor to the camera.

5. Send a signal
Click «Done», deploy and press the button of «part detected». The delay node shows a dot while it holds the message, and 2 seconds later the debug panel shows it arrive at «take a picture».

6. Notice when the signals stop
Add a trigger node after «part detected» and a debug node after it. Open the trigger node. Set «Send» to «nothing», «then» to «wait for» 5 seconds, tick «extend delay if new message arrives», and set «then send» to the text line stopped. Each signal starts the wait again, so the message only goes out when no part has arrived for 5 seconds: a watchdog for a line that stopped.

7. Test the watchdog
Click «Done», deploy and press «part detected» a few times. While the signals keep coming, the trigger node waits. 5 seconds after the last one, it sends «line stopped»: wire it to a panel, a light or an email to warn the operators.

Good to know
- The controller's clock. «at a specific time» and «interval between times» follow the time zone of the controller, which may not be yours.
- A rate instead of a delay. Set the delay node's «Action» to «Rate Limit» to let through at most so many messages per second and drop or queue the rest. To pace images, see Control the pace of a flow.
- Repeat while a signal lasts. In the trigger node, «then» «resend it every» repeats the message until a message with
msg.resetarrives: a blinking light while the line is stopped. - Start once at deploy. «Inject once after 0.1 seconds» sends one message each time the flow starts: after a deploy and after the controller restarts. Use it to load settings when the flow starts; see Remember values between messages and restarts.
Next steps
Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.